package com.szc.demo01.controller.boss;
import com.szc.demo01.controller.base.BaseController;
import com.szc.demo01.exception.NotBossException;
import com.szc.demo01.pojo.Attence;
import com.szc.demo01.service.AttenceService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
public class AttenceBossController extends BaseController {
    @Autowired
    private AttenceService attenceService;

    @GetMapping(value = "/boss_view_show")
    public String boss_view(Model model) throws NotBossException {
        assertUserIdHasPerm(6);

        Date date=new Date(System.currentTimeMillis());
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("MM");
        String format = simpleDateFormat.format(date);
        Integer month=Integer.parseInt(format);
        List<Attence> listForBoss = attenceService.getListForBoss(null, month, null);

        model.addAttribute("list",attenceService.getListForBoss(null,month,null));
        return "attendance/boss_view";
    }

    /**
     * 按月份查找
     * @param month
     * @param e_id
     * @param name
     * @param model
     * @return
     */
    @GetMapping(value = "/research_by_month_or_name_or_id")
    @ResponseBody
    public List<Attence> researchByMonthOrNameOrEid(@Param("month")Integer month, @Param("e_d")Integer e_id, @Param("name")String name, Model model) throws NotBossException {
        assertUserIdHasPerm(6);

        if(e_id!=null&&name!=null){
           return attenceService.getListForBoss((long)e_id,month,name);
        }else if(e_id!=null &&name==null){
            return  attenceService.getListForBoss((long)e_id,month,null);
        }else {
            return attenceService.getListForBoss(null,month,name);
        }
    }

    /**
     * 按天查询
     * @param work_date
     * @return
     */
    @GetMapping(value = "/research_by_day")
    @ResponseBody
    public List<Attence>researchByDay(@Param("date")String work_date) throws NotBossException {
        assertUserIdHasPerm(6);
        return attenceService.getListForBossByDay(work_date);
    }

    //请假审批
    @GetMapping(value = "/boss_view_approval")
    public String approval(){
        return "attendance/approval";
    }
}
